//Shows error message as popup window
//To write own function for showing validation errors use the next pattern.
//
//
//IMPORTANT!!!!
// - Write own function "displayErrors"
// - Use array of errors messages as variable              this._messagesText
// - You must to insert id for the error message tag as    this._idError
// - Use this._element as DOM element that is validated    this._element

dojo.provide("dojo.app.myvalidatorDijit.errorviews.popup");

dojo.declare("dojo.app.myvalidatorDijit.errorviews.popup", null, {
    _element : null,
    _idError : "",
    _messagesText : [],

    constructor: function(element, idError, messagesText) {
        this._element = element;
        this._idError = idError;
        this._messagesText = messagesText;
    },

    displayErrors: function() {
        var validatedElem = this._element.domNode;

        var posElement = dojo.coords(validatedElem);
        var message = this._messagesText.join("");

        var em = dojo.query(dojo.create('em', {id : this._idError, innerHTML : message})).place(validatedElem, "after");
        em.addClass("error");
        var posError = dojo.coords(em[0]);

        dojo.animateProperty({node: em[0], duration:500,
            properties: {
                opacity: { start: 0, end: 0.9 },              
                marginLeft: { start:10, end:5, unit:"px"  }  
            },
            beforeBegin: function() {
                em.style({top : (posElement.t-posError.h/2+5).toString()+"px"});
                em.style({display : 'inline'});
            }
        }).play();
        
    }
});


